using System;
using System.Collections.Generic;
using System.Text;
using agsXMPP.protocol.client;

namespace SwinMessengerLibrary
{
    public class Contact
    {
        private ContactStatus _Status;

        public ContactStatus Status
        {
            get { return _Status; }
            set { _Status = value; }
        }
        private string _Id;
        private Roster _Parent;

        public Roster Parent
        {
            get { return _Parent; }
        }
        private bool _CanClose;

        public bool CanClose
        {
            get { return _CanClose; }
            set { _CanClose = value; }
        }

        public string Id
        {
            get { return _Id; }
            set { _Id = value; }
        }
        private string _Name;

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        public event EventHandler OnMessage;

        public Contact(Roster parent, string id, string name)
        {
            _Id = id;
            _Name = name;
            _Status = ContactStatus.Offline;
            _Parent = parent;
            _CanClose = true;
        }

        public void Chat(string message, string state)
        {
            MessageEventArgs e = new MessageEventArgs(_Id, message, state);
            if (OnMessage != null)
            {
                OnMessage(this, e);
            }
        }

        public void SendTo(string message)
        {
            _Parent.SendTo(_Id, message);
        }

        public void Update(Contact contact)
        {
            _Id = contact.Id;
            _Name = contact.Name;
            _Parent = contact.Parent;
            _Status = contact.Status;
        }

        public void Close()
        {
            if (OnClose != null)
            {
                OnClose(this, EventArgs.Empty);
            }
        }

        public event EventHandler OnClose;
    }
}
